package org.jsola.hr.web;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.jsola.admin.vo.HeaderFieldsVO;
import org.jsola.contract.dto.ContractUpdateDTO;
import org.jsola.contract.dto.EnterpriseSignDTO;
import org.jsola.contract.dto.IssuedCategoryAddDTO;
import org.jsola.contract.dto.PublishSignDTO;
import org.jsola.contract.query.ContractGroupQuery;
import org.jsola.contract.query.ContractQuery;
import org.jsola.contract.query.SealQuery;
import org.jsola.contract.vo.*;
import org.jsola.core.Page;
import org.jsola.core.Result;
import org.jsola.hr.dto.HrContractDownloadDTO;
import org.jsola.hr.dto.HrCategoryUpdateDTO;
import org.jsola.hr.dto.TemplateVariableUpdateDTO;
import org.jsola.hr.dto.contract.AddSealDTO;
import org.jsola.hr.dto.contract.UpdateSealDTO;
import org.jsola.hr.dto.contract.VerifyEnterpriseDTO;
import org.jsola.hr.query.HrContractExportQuery;
import org.jsola.hr.vo.FailCategoryVO;
import org.jsola.hr.vo.HrContractListVO;
import org.jsola.hr.vo.HrVariableListVO;
import org.springframework.core.io.Resource;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestBody;

import javax.validation.Valid;
import java.util.List;
import java.util.Map;

/**
 * @author JanusMix
 */
@Api(tags = "hr-合同管理")
public interface IContractControllerAPI {


    @ApiOperation(value = "新增印章")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "addSealDTO", dataType = "AddSealDTO", value = "新增印章", paramType = "body")
    })
    Result<SealVO> saveSeal(AddSealDTO addSealDTO);

    @ApiOperation(value = "修改印章")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "sealUpdateDTO", dataType = "UpdateSealDTO", value = "修改印章", paramType = "body")
    })
    Result<Integer> updateSeal(UpdateSealDTO sealUpdateDTO);

    @ApiOperation(value = "根据id查询印章详情")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "sealId", dataType = "Long", value = "印章id", paramType = "path")
    })
    Result<SealVO> selectSealById(Long sealId);

    @ApiOperation(value = "查询印章列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "sealQuery", dataType = "SealQuery", value = "印章查询对象", paramType = "query")
    })
    Result<List<SealListVO>> selectSealList(SealQuery sealQuery);

    @ApiOperation(value = "企业授权")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "verifyEnterpriseDTO", dataType = "VerifyEnterpriseDTO", value = "账户新增对象", paramType = "body")
    })
    Result<String> verifyEnterprise(VerifyEnterpriseDTO verifyEnterpriseDTO);

    @ApiOperation(value = "查询员工合同列表(小程序专用)")
    Result<List<PartySignListVO>> selectUserContractList();

    @ApiOperation(value = "根据id查询合同类型")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "categoryId", dataType = "Long", value = "分类id", paramType = "path")
    })
    Result<CategoryVO> selectCategoryById(Long categoryId);

    @ApiOperation(value = "获取模板变量map列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "templateId", dataType = "Long", value = "分类id", paramType = "path")
    })
    Result<List<Map<String, Object>>> selectVariableList(Long templateId);

    /**
     * 根据条件下载合同文件
     *
     * @param hrContractDownloadDTO 合同下载所需参数
     * @return 文件
     */
    @ApiOperation(value = "根据条件下载合同文件")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "hrContractDownloadDTO", value = "合同下载所需参数", dataType = "HrContractDownloadDTO", paramType = "body")
    })
    ResponseEntity<Resource> downloadContract(HrContractDownloadDTO hrContractDownloadDTO);

    @ApiOperation(value = "根据合同id删除合同及相关信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "contractId", dataType = "Long", value = "合同id", paramType = "path")
    })
    Result<String> deleteContractAndRelationById(Long contractId);

    /**
     * 导出合同列表(单租户)
     *
     * @param hrContractExportQuery 查询参数
     * @return 合同列表
     */
    @ApiOperation(value = "根据公司id导出合同列表")
    @ApiImplicitParam(name = "hrContractExportQuery", dataType = "HrContractExportQuery"
            , value = "合同导出查询参数", paramType = "body")
    ResponseEntity<Resource> exportContractBySubjectId(HrContractExportQuery hrContractExportQuery);

    /**
     * 导出合同列表(多租户)
     *
     * @param hrContractExportQuery 查询参数
     * @return 合同列表
     */
    @ApiOperation(value = "导出合同列表(多租户)")
    @ApiImplicitParam(name = "hrContractExportQuery", dataType = "HrContractExportQuery"
            , value = "合同导出查询参数", paramType = "body")
    ResponseEntity<Resource> exportAllContract(HrContractExportQuery hrContractExportQuery);

    /**
     * 分页查询用工单位排名
     *
     * @param contractQuery 查询参数
     * @return page
     */
    @ApiOperation(value = "分页查询用工单位排名")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "contractQuery", dataType = "ContractQuery", value = "合同查询参数", paramType = "query")
    })
    Result<Page<ContractStatisticsEmpUnitsVO>> selectComCountPage(ContractQuery contractQuery);

    /**
     * 分页查询用工单位排名(会根据业务ids查询)
     *
     * @param contractQuery 查询参数
     * @return page
     */
    @ApiOperation(value = "分页查询用工单位排名(会根据业务ids查询)")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "contractQuery", dataType = "ContractQuery", value = "合同查询参数", paramType = "body")
    })
    Result<Page<ContractStatisticsEmpUnitsVO>> selectComForRankCountPost(ContractQuery contractQuery);


    /**
     * 分页查询合同
     *
     * @param contractQuery 合同查询参数
     * @return page
     */
    @ApiOperation(value = "分页查询合同")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "contractQuery", dataType = "ContractQuery", value = "合同查询参数", paramType = "query")
    })
    Result<Page<ContractListVO>> pageContract(ContractQuery contractQuery);

    /**
     * 分页查询合同（业务id可以传多个）
     *
     * @param contractQuery 合同查询参数
     * @return page
     */
    @ApiOperation(value = "分页查询合同（业务id可以传多个）")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "contractQuery", dataType = "ContractQuery", value = "合同查询参数", paramType = "body")
    })
    Result<Page<HrContractListVO>> selectPageBySubjectIds(ContractQuery contractQuery);


    /**
     * 查询模板变量 个人信息拉取花名册
     *
     * @param companyId 公司Id
     * @param fieldName 字段名称 模糊查询
     * @return 模板变量列表信息
     */
    @ApiOperation(value = "查询模板变量 个人信息拉取花名册")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "companyId", dataType = "String", value = "公司Id", paramType = "query"),
            @ApiImplicitParam(name = "fieldName", dataType = "String", value = "字段名称 模糊查询", paramType = "query")
    })
    Result<List<HrVariableListVO>> pageContract(String companyId, String fieldName);


    /**
     * 批量编辑、新增、删除合同模板关联变量
     *
     * @param templateVariableUpdateDTO 要操作的合同模板关联变量
     * @return 操作之后的全部合同模板关联变量
     */
    @ApiOperation(value = "批量编辑、新增、删除合同模板关联变量")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "templateVariableUpdateDTO", dataType = "TemplateVariableUpdateDTO"
                    , value = "要操作的字段数据", paramType = "body")
    })
    Result<String> updateTemplateVariable(@Valid @RequestBody TemplateVariableUpdateDTO templateVariableUpdateDTO);


    /**
     * 根据合同pdf转图片放到合同文件中(签署完调用)
     *
     * @param contractId 合同id
     * @return 1
     */
    @ApiOperation(value = "根据合同pdf转图片放到合同文件中(签署完调用)")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "contractId", value = "合同id", dataType = "Long", paramType = "path")
    })
    Result<Integer> setJpgToAppendix(Long contractId);

    /**
     * 根据合同pdf转图片放到合同文件中(批量)
     *
     * @param contractIds 合同id List
     * @return 1
     */
    @ApiOperation(value = "根据合同pdf转图片放到合同文件中(批量)")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "contractIds", value = "合同id", dataType = "Long", paramType = "body")
    })
    Result<Integer> setJpgToMoreAppendix(List<Long> contractIds);


    /**
     * 下发合同模版到公司
     *
     * @param issuedCategoryAddDTO 合同模版
     * @return 合同类型
     */
    @ApiOperation(value = "下发合同模版到公司")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "issuedCategoryAddDTO", dataType = "IssuedCategoryAddDTO", value = "合同模版", paramType = "body")
    })
    Result<List<FailCategoryVO>> saveIssuedCategory(IssuedCategoryAddDTO issuedCategoryAddDTO);

    /**
     * 查询电子合同签署记录表头字段
     *
     * @param companyId 公司Id
     * @return 电子合同签署记录表头字段
     */
    @ApiOperation(value = "查询电子合同签署记录表头字段")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "companyId", dataType = "String", value = "公司Id", paramType = "query")
    })
    Result<HeaderFieldsVO> getSignedRecordHead(String companyId);

    /**
     * 查询管理后台电子合同签署记录表头字段
     *
     * @param companyId 公司Id
     * @return 电子合同签署记录表头字段
     */
    @ApiOperation(value = "查询管理后台电子合同签署记录表头字段")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "companyId", dataType = "String", value = "公司Id", paramType = "query")
    })
    Result<HeaderFieldsVO> getAdminSignedRecordHead(String companyId);


    /**
     * 修改合同名称
     *
     * @param contractUpdateDTO 修改合同信息
     * @return 修改条数
     */
    @ApiOperation(value = "修改合同名称")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "contractUpdateDTO", dataType = "ContractUpdateDTO", value = "修改合同信息", paramType = "body")
    })
    Result<Integer> updateContractName(ContractUpdateDTO contractUpdateDTO);

    /**
     * 修改合同备注
     *
     * @param contractUpdateDTO 修改合同备注
     * @return 修改条数
     */
    @ApiOperation(value = "修改合同名称")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "contractUpdateDTO", dataType = "ContractUpdateDTO", value = "修改合同信息", paramType = "body")
    })
    Result<Integer> updateContractNo(ContractUpdateDTO contractUpdateDTO);

    /**
     * 修改合同名称/修改合同备注
     *
     * @param contractUpdateDTO 修改合同备注
     * @return 修改条数
     */
    @ApiOperation(value = "修改合同名称/修改合同备注")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "contractUpdateDTO", dataType = "ContractUpdateDTO", value = "修改合同信息", paramType = "body")
    })
    Result<Integer> updateContractNameOrContractNo(ContractUpdateDTO contractUpdateDTO);


    @ApiOperation(value = "发起模板签署")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "publishSignDTO", dataType = "PublishSignDTO", value = "发起模板签署对象", paramType = "body")
    })
    Result<List<ContractVO>> publishTemplateSign(PublishSignDTO publishSignDTO);

    @ApiOperation(value = "发起模板签署(异步)")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "publishSignDTO", dataType = "PublishSignDTO", value = "发起模板签署对象", paramType = "body")
    })
    Result<String> publishTemplateSignAsync(PublishSignDTO publishSignDTO);

    @ApiOperation(value = "批量发起合同")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "enterpriseSignDTO", dataType = "EnterpriseSignDTO", value = "企业签署对象", paramType = "body"),
    })
    Result enterpriseSignAgainBatch(EnterpriseSignDTO enterpriseSignDTO);

    /**
     * 批量删除合同，彻底删除
     *
     * @param contractIds 合同id集合
     * @return 删除数量
     */
    @ApiOperation(value = "批量删除合同，彻底删除")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "contractIds", dataType = "Long[]", value = "合同id数组", paramType = "body", allowMultiple = true)
    })
    Result<Integer> deleteContractBatch(Long[] contractIds);

    /**
     * 查询合同类型分组 同时同步默认分组
     *
     * @param contractGroupQuery 查询条件
     * @return 合同类型分组列表信息
     */
    @ApiOperation(value = "查询合同类型分组 同时同步默认分组")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "contractGroupQuery", dataType = "ContractGroupQuery"
                    , value = "查询条件", paramType = "query")
    })
    Result<List<ContractGroupListVO>> selectAndSynchronizeContractGroup(ContractGroupQuery contractGroupQuery);


    /**
     * 用工单位修改合同类型、合同模板、模板关联变量
     *
     * @param hrCategoryUpdateDTO 合同类型、合同模板、模板关联变量修改内容
     * @return 无
     */
    @ApiOperation(value = "用工单位修改合同类型、合同模板、模板关联变量")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "hrContractUpdateDTO", dataType = "HrContractUpdateDTO"
                    , value = "合同类型、合同模板、模板关联变量修改内容", paramType = "body")
    })
    Result<Integer> updateCategoryByCompany(HrCategoryUpdateDTO hrCategoryUpdateDTO);

}
